package com.infore.remoteControl.serviceBetweenInterface.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.remoteControl.constant.Constants;
import com.infore.remoteControl.enums.ResultStatus;
import com.infore.remoteControl.remoteService.IStationManageService;
import com.infore.remoteControl.serviceBetweenInterface.service.IRemoteControlAndStationManageService;
import com.infore.remoteControl.util.ResultEntity;

@Service
public class RemoteControlAndStationManageServiceImpl implements IRemoteControlAndStationManageService {
	
	@Autowired
	IStationManageService iStationManageService;

	@SuppressWarnings("unchecked")
	@Override
	public ResultEntity stations(String protocolDataId) {
		// 根据协议数据ID获取站点信息
		ResultEntity resultEntity = iStationManageService.getStationByProtocol(protocolDataId);
		if (resultEntity.getCode() == 1) {
			return new ResultEntity(ResultStatus.ERROR, Constants.QUERY_FAILUE);
		}
		Map<String, Object> contentMap = (Map<String, Object>) resultEntity.getContent();
		List<Map<String, Object>> dataList = (List<Map<String, Object>>) contentMap.get("dataList");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		// 重新封装站点信息(目前只抽取站点ID,站点名称)
		for (Map<String, Object> dataMap : dataList) {
			Map<String, Object> map = new HashMap<String, Object>();
			String stationId = dataMap.get("stationId").toString();
			String stationName = dataMap.get("stationName").toString();
			map.put("stationId", stationId);
			map.put("stationName", stationName);
			list.add(map);
		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

	@SuppressWarnings("unchecked")
	@Override
	public ResultEntity equipment(String instructionsId) {
		// 根据指令ID获取设备信息
		ResultEntity resultEntity = iStationManageService.getEquipmentByInstructions(instructionsId);
		if (resultEntity.getCode() == 1) {
			return new ResultEntity(ResultStatus.ERROR, Constants.QUERY_FAILUE);
		}
		Map<String, Object> contentMap = (Map<String, Object>) resultEntity.getContent();
		List<Map<String, Object>> dataList = (List<Map<String, Object>>) contentMap.get("dataList");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		// 重新封装设备信息(目前只抽取设备ID,设备名称)
		for (Map<String, Object> dataMap : dataList) {
			Map<String, Object> map = new HashMap<String, Object>();
			String equipmentId = dataMap.get("equipmentId").toString();
			String equipmentName = dataMap.get("equipmentName").toString();
			map.put("equipmentId", equipmentId);
			map.put("equipmentName", equipmentName);
			list.add(map);
		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
}
